import router from '@/router'
import {useMenuStore} from '@/stores/menu'
import { useUserStore } from '@/stores/user'

const whiteRoute = ['/chat' , '/contact' , '/collection']
const userStore = useUserStore()

const menuStore = useMenuStore()

const openRouteList = ['/login']

router.beforeEach((to, from, next) => {

  let flag = false

  openRouteList.forEach(item => {
    if (to.path === item) {
      console.log('直接放行')
      next()
      flag = true
    }
  })

  if (flag) {
    return
  }


  if (!userStore.uid) {
    userStore.userInfo()
  }


  menuStore.showOperate = false
  for (let i = 0; i < whiteRoute.length; i++) {
    if ( whiteRoute[i] === to.path ) {
      menuStore.showOperate = true
      break;
    }
  }

  next()
})
